﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace PJ.Data
{
    public abstract class EntityProviderClient<S, D> : ObjectProviderClient<S, D>, IEntityProvider<D>
        where D : BaseEntityData, new()
        where S : class, IEntityProvider<D>
    {
        protected EntityProviderClient() {
        }
        
        protected EntityProviderClient(string endpointConfigurationName) : 
                base(endpointConfigurationName) {
        }
        
        protected EntityProviderClient(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        protected EntityProviderClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        protected EntityProviderClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress) {
        }

        public D GetById(string Id)
        {
            if (string.IsNullOrEmpty(Id))
                throw new ArgumentNullException();
            return base.Channel.GetById(Id);
        }
        public D FindById(string Id)
        {
            if (string.IsNullOrEmpty(Id))
                throw new ArgumentNullException();
            return base.Channel.FindById(Id);
        }

        public D CachedGetById(string Id)
        {
            if (string.IsNullOrEmpty(Id))
                throw new ArgumentNullException();
            return base.Channel.CachedGetById(Id);
        }
        public D CachedFindById(string Id)
        {
            if (string.IsNullOrEmpty(Id))
                throw new ArgumentNullException();
            return base.Channel.CachedFindById(Id);
        }

        #region Interface override
        IEntityData IEntityProvider.GetById(string id)
        {
            return GetById(id);
        }

        IEntityData IEntityProvider.CachedGetById(string id)
        {
            return CachedGetById(id);
        }

        IEntityData IEntityProvider.FindById(string id)
        {
            return GetById(id);
        }

        IEntityData IEntityProvider.CachedFindById(string id)
        {
            return GetById(id);
        }
        #endregion

    }
}
